{extend name="adminblue/base" /}
{block name="resources"/}
<style type="text/css">
#albumList{overflow:hidden;}
.input-file{position: absolute;top: -10px !important;right: 9px !important;height: 26px !important;width: 94px !important;filter: alpha(opacity : 0) !important; opacity: 0 !important;line-height:auto;}
.qrcode_button{
background-color:#51a351;border:none;margin-top:15px;width:100%;color:#FFF;padding: 5px 10px;}
.check{position: absolute;bottom:0px;width: 100%;height: 100%;right: -1px;background-color: rgba(0,0,0,0.8);display:none;}
.check div{width:60%;height:30px;margin-left:20%;border:1px solid #fff;margin-top:10%;text-align:center;}
.check div:hover{background: #126AE4;border:1px solid #126AE4;}
.check div span{font-size:15px;color:#fff;line-height:30px;}
.options-btn{padding-bottom:0px;}
</style>
{/block}
{block name="main"}
<div class="options-btn">
	<button class="btn-common btn-small" onclick="load_url()">添加自定义模板</button>
</div>
<div id="pictureIndex" class="ncsc-picture-folder">
	<div class="ncsc-album">
		<div style="clear:both;"></div>
		<ul id="albumList" >
		{foreach name="template_list" item="info"}
		{if condition="($key+2)%4 ==0 "} 
			<li style="opacity: 1;height:auto;position:relative;width:19%;float:left;margin-right:1%;margin-top:10px;margin-bottom:10px;" onmouseover="checkShowThis(this);"  onmouseout="checkHideThis(this);" >			
		{else /} 
			<li style="opacity: 1;height:auto;position:relative;width:19%;float:left;margin-right:1%;margin-top:10px;margin-bottom:10px;" onmouseover="checkShowThis(this);"  onmouseout="checkHideThis(this);" >
		{/if}
		{if condition="$info.is_check == 1 "} 
				{if condition='file_exists("$info[template_url]")'}
				<img src="{:__IMG($info.template_url)}" style="border:1px solid #00C0FF;"/>
				{else /}
				<img src="__STATIC__/images/qrcode_bg/template_bg_img.png" style="border:1px solid #00C0FF;"/>
				{/if}
		{else /}
				{if condition='file_exists("$info[template_url]")'}
				<img src="{:__IMG($info.template_url)}" style="border:1px solid #eee;"/>
				{else /}
				<img src="__STATIC__/images/qrcode_bg/template_bg_img.png" style="border:1px solid #eee;"/>
				{/if}
		{/if}
				<div class="check" >
				{if condition="$info.is_check == 1 "} 
					<div onclick="modifyWeixinQrcode({$info.id})" style="margin-top:60%;cursor:pointer;">
						<span>编辑</span>
					</div>
					{else /}
					<div style="margin-top:50%;cursor:pointer;" onclick="modifyWeixinQrcodeTemplateValid({$info.id})">
						<span >设为默认</span>
					</div>
					<div onclick="deleteWeixinQrcodeTemplateValid({$info.id})" style="cursor:pointer;">
						<span>删除</span>
					</div>
					<div onclick="modifyWeixinQrcode({$info.id})" style="cursor:pointer;">
						<span>编辑</span>
					</div>
					{/if}
				</div>
				<input type="hidden" class="id" value="{$info.id}"/>
				<input type="hidden" class="background" value="{$info.background}"/>
				<input type="hidden" class="nick_font_color" value="{$info.nick_font_color}"/>
				<input type="hidden" class="nick_font_size" value="{$info.nick_font_size}"/>
				<input type="hidden" class="is_logo_show" value="{$info.is_logo_show}"/>
				<input type="hidden" class="header_left" value="{$info.header_left}"/>
				<input type="hidden" class="header_top" value="{$info.header_top}"/>
				<input type="hidden" class="name_left" value="{$info.name_left}"/>
				<input type="hidden" class="name_top" value="{$info.name_top}"/>
				<input type="hidden" class="logo_left" value="{$info.logo_left}"/>
				<input type="hidden" class="logo_top" value="{$info.logo_top}"/>
				<input type="hidden" class="code_left" value="{$info.code_left}"/>
				<input type="hidden" class="code_top" value="{$info.code_top}"/>
				<div>
					{if condition="$info.is_check == 1 "} 
						<img src="ADMIN_IMG/check_qrcode1.png" class="qrcode_img" style="position:absolute;top:0px;left:1px;"/>
					{else /} 
						<img src="ADMIN_IMG/check_qrcode1.png" class="qrcode_img" style="position:absolute;top:0px;leftt:1px;display:none;"/>
					{/if}
				</div>
			</li>
		{/foreach}
		</ul>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
function checkShowThis(event){
	$(".qrcode_button").hide();
	$(".check").hide();
	$(event).find(".qrcode_button").show();
	$(event).find(".check").show();
}
function checkHideThis(event){
	$(event).find(".qrcode_button").hide();
	$(event).find(".check").hide();
}

//上传配置
function save(event){
	var background = $(event).parent().parent().children(".background").val();
	var nick_font_color = $(event).parent().parent().children(".nick_font_color").val();
	var nick_font_size = $(event).parent().parent().children(".nick_font_size").val();
	var is_logo_show = $(event).parent().parent().children(".is_logo_show").val();
	var header_left = $(event).parent().parent().children(".header_left").val();
	var header_top = $(event).parent().parent().children(".header_top").val();
	var name_left = $(event).parent().parent().children(".name_left").val();
	var name_top = $(event).parent().parent().children(".name_top").val();
	var logo_left =$(event).parent().parent().children(".logo_left").val();
	var logo_top = $(event).parent().parent().children(".logo_top").val();
	var code_left = $(event).parent().parent().children(".code_left").val();
	var code_top = $(event).parent().parent().children(".code_top").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/wchat/qrcode')}",
		data : {
			'background' : background,
			'nick_font_color' : nick_font_color,
			'nick_font_size' : nick_font_size,
			'is_logo_show' : is_logo_show,
			'header_left' : header_left,
			'header_top' : header_top,
			'name_left' : name_left,
			'name_top' : name_top,
			'logo_left' : logo_left,
			'logo_top' : logo_top,
			'code_left' : code_left,
			'code_top' : code_top
		},
		success : function(data) {
			if(data['code'] > 0){
				showTip(data['message'],"success");
				location.href = "{:__URL('ADMIN_MAIN/wchat/weixinqrcodetemplate')}";
			}else{
				showTip(data['message'],"error");
			}
		}
	})
}

//设置店铺的模板为默认
function modifyWeixinQrcodeTemplateValid(id){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/wchat/modifyweixinqrcodetemplatevalid')}",
		data : { 'id' : id },
		success : function(data) {
			if(data['code'] > 0){
				showTip(data['message'],"success");
				location.href = "{:__URL('ADMIN_MAIN/wchat/weixinqrcodetemplate')}";
			}else{
				showTip(data['message'],"error");
			}
		}
	})
}

function deleteWeixinQrcodeTemplateValid(id){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/wchat/deleteweixinqrcodetemplatevalid')}",
		data : { 'id' : id },
		success : function(data) {
			if(data['code'] > 0){
				showTip(data['message'],"success");
				location.href = "{:__URL('ADMIN_MAIN/wchat/weixinqrcodetemplate')}";
			}else{
				showTip(data['message'],"error");
			}
		}
	})
}

function load_url(){
	window.location.href="{:__URL('ADMIN_MAIN/wchat/qrcode')}";
}

function modifyWeixinQrcode(id){
	window.location.href=__URL('ADMIN_MAIN/wchat/qrcode?id=' + id);
}
</script>
{/block}